package com.ude.pim.controller;

import com.ude.pim.common.R;
import com.ude.pim.dto.CaseSubCommentDTO;
import com.ude.pim.entity.Case;
import com.ude.pim.entity.CaseSubComment;
import com.ude.pim.service.CaseSubCommentService;
import com.ude.pim.service.CaseSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yb
 * @since 2023-08-08
 */
@RestController
@RequestMapping("/caseSubComment")
public class CaseSubCommentController {
    @Autowired
    private CaseSubCommentService caseSubCommentService;

    /**
     * 查询某个子流程已审核的备注
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<List<CaseSubComment>> getListByCaseSubId(@PathVariable("id") Long id){
        return caseSubCommentService.getListByCaseSubId(id);
    }

    @PostMapping
    public R<String> save(@RequestBody CaseSubComment caseSubComment){
        caseSubComment.setStatus(0);
        caseSubCommentService.save(caseSubComment);
        return R.success("备注保存成功");
    }

    /**
     * 获取所有未审核的子流程备注
     * @return
     */
    @GetMapping("/pendingList")
    public R<List<CaseSubCommentDTO>> getPendingReview(){
        return caseSubCommentService.getPendingReview();
    }

    /**
     * 审核通过
     */
    @PutMapping
    public R<String> passCheck(@RequestBody CaseSubComment caseSubComment){
        System.out.println(caseSubComment);
        caseSubCommentService.updateById(caseSubComment);
        return R.success("审核通过");
    }

    @PostMapping("/byUserAndStatus")
    public R<List<CaseSubCommentDTO>> getByUserAndStatus(@RequestBody CaseSubComment caseSubComment){
        return caseSubCommentService.getByUserAndStatus(caseSubComment);
    }
}
